@extends("layout.admin")

@section("title")
    系统日志列表
@endsection

@section("content")
    <div class="layui-card-body ">
        {{--搜索--}}
        <form class="layui-form layui-col-space5 layui-input-inline" id="search-form">
            <div class="demoTable">
                <div class="layui-inline">
                    <select name="level">
                        <option value="">全部等级</option>
                        @foreach($level as $k=>$v)
                            <option value="{{$k}}" @if($k == request('level'))selected="selected"@endif>{{$v}}</option>
                        @endforeach
                    </select>
                </div>
                <div class="layui-inline" id="test6">
                    <input type="text" class="layui-input" name="date" value="{{request('date')}}" id="date" placeholder="请选择时间">
                </div>
                <div class="layui-inline">
                    <select name="module" lay-filter="module">
                        <option value="">全部模块</option>
                        @foreach($module as $k=>$v)
                            <option value="{{$k}}" @if($k == request('module'))selected="selected"@endif>{{$v}}</option>
                        @endforeach
                    </select>
                </div>
                <div class="layui-inline">
                    <select name="config" lay-filter="config" id="config">
                        <option value="">全部操作</option>
                        @foreach($config as $k=>$v)
                            <option value="{{$k}}" @if($k == request('config'))selected="selected"@endif>{{$v}}</option>
                        @endforeach
                    </select>
                </div>
                <div class="layui-inline">
                    <input class="layui-input" name="real_name" id="real_name" style="width: 100% !important;"
                           value="{{request('real_name')}}" placeholder="请输入真实姓名">
                </div>
                <div class="layui-inline layui-show-xs-block">
                    <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i>
                    </button>
                </div>
            </div>
        </form>
    </div>
    {{--列表--}}
    <div class="layui-card-body ">
        <script type="text/html" id="toolbar">

        </script>
        <table lay-filter="table-hide" style="display: none"  lay-data="{height:'full-310', cellMinWidth: 80,toolbar: '#toolbar',defaultToolbar:['filter'],limit:{{$list['per_page']}}}">
            <thead>
            <tr>
                <th lay-data="{field:'id',width:80, fixed: 'left', unresize: true, sort: true}">编号</th>
                <th lay-data="{field:'real_name'}">用户名</th>
                <th lay-data="{field:'message',width:380,}">操作</th>
                <th lay-data="{field:'level'}">日志等级</th>
                <th lay-data="{field:'data'}">数据</th>
                <th lay-data="{field:'created_at'}">时间</th>
                <th lay-data="{field:'ip'}">IP</th>
            </tr>
            </thead>
            <tbody>
            @foreach ($list['data'] as $vo)
                <tr>
                    <td>{{ $vo['id'] }}</td>
                    <td>{{ $vo['real_name'] }}</td>
                    <td>{{ $vo['message'] }}</td>
                    <td>{{ $vo['level'] }}</td>
                    <td>
                        <a class="layui-btn layui-btn-primary layui-btn-xs" onclick="selectData({{$vo['data']}})">查看数据</a>
                    </td>
                    <td>{{ $vo['created_at'] }}</td>
                    <td>{{ $vo['ip'] }}</td>
                </tr>
            @endforeach
            </tbody>
        </table>
        @include("layout.page")
    </div>
@endsection

@section('script')
    <script>
        function selectData(data){
            data = JSON.stringify(data)
            layui.layer.msg(data);
        }
        var idx=-1;
        layui.use(['form', 'table', 'layer','laydate'], function () {
            var table = layui.table;
            var form = layui.form, laydate = layui.laydate;
            laydate.render({
                elem: '#date'
                ,range: '~'
            });
            table.init("table-hide");
            admin.paginate("{{ $list['total'] }}", "{{ $list['current_page'] }}", "{{ $list['per_page'] }}");
            form.on("select(module)",function(data){
                $.get("{{route('admin.log.getModuleConfig')}}",{value:data.value},function(data){
                    var html = "<option value=\"\">全部操作</option>";
                    $.each(data,function(index,item){
                        html+="<option value='"+index+"'>"+item+"</option>"
                    })
                    $("#config").html(html);
                    form.render('select')
                })
            })

        });

    </script>
    <script src="{{asset('js/layCommon.js')}}"></script>
@endsection

